# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=npth
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.8
pkgrel=1
pkgdesc="New portable threads library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
license=('LGPL')
url="https://gnupg.org/"
msys2_repository_url="https://git.gnupg.org/cgi-bin/gitweb.cgi?p=npth.git"
msys2_pgp_keys_url='https://gnupg.org/signature_key.html'
validpgpkeys=(
  '5B80C5754298F0CB55D8ED6ABCEF7E294B092E28' # Andre Heinecke (Release Signing Key)
  '6DAA6E64A76D2840571B4902528897B826403ADA' # Werner Koch (dist signing 2020)
  'AC8E115BF73E2D8D47FA9908E98E9B2D19C6C8BD' # Niibe Yutaka (GnuPG Release Key)
  '02F38DFF731FF97CB039A1DA549E695E905BA208' # GnuPG.com (Release Signing Key 2021)
)
source=("https://gnupg.org/ftp/gcrypt/${_realname}/${_realname}-${pkgver}.tar.bz2"{,.sig})
sha256sums=('8bd24b4f23a3065d6e5b26e98aba9ce783ea4fd781069c1b35d149694e90ca3e'
            'SKIP')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  # autoreconf to get updated libtool files with clang support
  autoreconf -fiv
}

build() {
  [ -d "${srcdir}"/build-${MSYSTEM} ] && rm -rf "${srcdir}"/build-${MSYSTEM}
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST}

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make -j1 DESTDIR="${pkgdir}" install
}
